package api

import (
	"enjoy_xxz/base"
	"enjoy_xxz/formdata"
	"enjoy_xxz/internal/server"
	"enjoy_xxz/pkg"
	"fmt"
	"github.com/gin-gonic/gin"
)

// 添加购物车
func CreateCart(c *gin.Context) {
	userID := pkg.GetAutoUserID(c)
	var data formdata.CreateCartReq
	if err := c.ShouldBindJSON(&data); err != nil {
		base.RespData(c, nil, err)
		return
	}
	fmt.Println("接收到的data", data.Quantity)
	err := server.CreateCart(data, userID)
	base.RespData(c, nil, err)
}

// 购物车 列表
func GetCartList(c *gin.Context) {
	userID := pkg.GetAutoUserID(c)
	list, err := server.GetCartList(int64(userID))
	fmt.Println("查询到的数据：：", list)
	base.RespData(c, list, err)
}

// 购物车修改
func CartUpdateByQuantity(c *gin.Context) {
	userID := pkg.GetAutoUserID(c)
	var data formdata.CreateCartReq
	if err := c.ShouldBindJSON(&data); err != nil {
		base.RespData(c, nil, err)
		return
	}
	err := server.CartUpdate(data, userID)
	base.RespData(c, nil, err)
}
